/**
 * Created by   :Wangshuzhong
 * Created time :2019/08/29
 */
require(["vue","ELEMENT"], function (Vue, Element) {
  // 微博微信qq分享
  //新浪微博分享部分
  var ShareTip = function() {}
  //分享到腾讯微博
  ShareTip.prototype.sharetoqq = function(content, url, picurl) {
    var shareqqstring = 'http://v.t.qq.com/share/share.php?title=' + content + '&url=' + url + '&pic=' + picurl;
    window.open(shareqqstring, 'newwindow', 'height=100,width=100,top=100,left=100');
  }
  //分享到新浪微博
  ShareTip.prototype.sharetosina = function(title, url, picurl) {
    var sharesinastring = 'http://v.t.sina.com.cn/share/share.php?title=' + title + '&url=' + url + '&content=utf-8&sourceUrl=' + url + '&pic=' + picurl;
    window.open(sharesinastring, 'newwindow', 'height=400,width=400,top=100,left=100');
  }
  //分享到QQ空间
  ShareTip.prototype.sharetoqqzone = function(title, url, picurl) {
    var shareqqzonestring = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?summary=' + title + '&url=' + url + '&pics=' + picurl;
    window.open(shareqqzonestring, 'newwindow', 'height=400,width=400,top=100,left=100');
  }

  // $(".a-weibo").click(function() {
  //   var share1 = new ShareTip();
  //   share1.sharetosina("从构建分布式秒杀系统聊聊限流特技", window.location.href, "");
  // })
  Vue.use(Element)
  var Config = $("body").data("config"); // 配置文件内容
  //设置导航栏
  window.app = new Vue({
      el: '#app',
      data: {
          activeName: 'about', // 显示的导航
          activeSecName: 'news', // 显示的二级导航
          pageInfo: {
            curPage: 1,
            pageSize: 10,
            code: 'info'
          },
          newsInfo: {},
          newsList: [],
          code: ''
      },
      created:function() {
        var urlData = Config.getSearchDataFun();
        this.code = urlData.code;
        // 获取动态新闻数据
        this.getNewsList();
        // 获取这条新闻详情
        this.getNewsInfo();
      },
      mounted:function() {
        var path = 'http://dfyz.cn.com:8201/newsInfo.html?code=' + this.code;
        console.log(path)
        $("#qrCode").qrcode({
          text: path, //设置二维码内容
          render: "canvas", //设置渲染方式
          width: 200, //设置宽度,默认生成的二维码大小是 256×256
          height: 200, //设置高度
          typeNumber: -1, //计算模式
          background: "#ffffff", //背景颜色
          foreground: "#000000" //前景颜色
        });
      },
      methods: {
          getNewsInfo:function() {
            var self = this;
            Config.Request('post', Config.apiUrl.getNewsInfo, {code: this.code}).then(function(res) {
              if(res.code == 200) {
                self.newsInfo = res.data;
                document.title = res.data.title;
                $("meta[name='keywords']").attr("content", res.data.keyword);
                $("meta[name='description']").attr("content", res.data.resume);
              } else {
                self.$message.error(res.message)
              }
            }).catch(function(error) {
              self.$message.error(error)
            })
          },
          // 获取动态新闻数据
          getNewsList:function() {
            var self = this;
            Config.Request('post', Config.apiUrl.getNews, this.pageInfo).then(function(res) {
              if(res.code == 200) {
                self.newsList = res.data;
              } else {
                self.$message.error(res.message)
              }
            }).catch(function(error) {
              self.$message.error(error)
            })
          },
          toNews:function(id) {
            window.location.href = 'newsInfo.html' + '?code=' + id;
          },
          // 分享
          toShare: function(type) {
            var shareObj = new ShareTip();
            if (type === 'wx') {
              shareObj.sharetosina(this.newsInfo.title, window.location.href, this.newsInfo.thumb_src);
            } else if(type === 'qq') {
              shareObj.sharetoqqzone(this.newsInfo.title, window.location.href, this.newsInfo.thumb_src);
            } else if(type === 'wb') {
              shareObj.sharetosina(this.newsInfo.title, window.location.href, this.newsInfo.thumb_src);
            }
          }
      }
  });
})
